﻿using System.Windows.Forms;
using MediaController.Client.Controls.Dialogs;
using MediaController.Client.DAL;
using System;

namespace MediaController.Client.Controls.UserControls
{
    public partial class PathManager : UserControl
    {
        public PathManager()
        {
            InitializeComponent();
            _mediaControllerDataSet = DataAccess.Instance.MediaControllerDataSet;
            _bindingSource.DataSource = _mediaControllerDataSet;
         
        }

        private void DataGridViewCellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (_dataGridView.Columns[e.ColumnIndex].HeaderText == "Destination" &&
                _dataGridView.Rows[e.RowIndex].Cells[1].Value != DBNull.Value)
            {
                var categoryId = _dataGridView.Rows[e.RowIndex].Cells[1].Value;
                var destinationBuilder = new DestinationBuilder(Convert.ToInt32(categoryId));
                destinationBuilder.Destination = _dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                if (destinationBuilder.ShowDialog(this) == DialogResult.OK)
                {
                    _dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = destinationBuilder.Destination;
                }
            }
        }
    }
}